using System.IO;

using OpenXmlWriter.Packaging;

namespace OpenXmlWriter.WordprocessingML.Packaging
{
  public class ImagePart : OpenXmlPart
  {
    private const string PartRelationshipType =
      "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";

    private const string PartPath = "word/media"; 
    public const string PartContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";
    private string _targetPath;

    public void Initialize(OpenXmlPackage openXmlPackage, OpenXmlPartContainer openXmlPartContainer, string fileName,
                           string contentType)
    {
      base.Initialize(openXmlPackage, openXmlPartContainer);

      _targetPath = CreateUniquePath(fileName);

      _contentType = new ContentType(Path.GetExtension(fileName).Remove(0, 1).ToLower(), contentType, true);
    }

    private string CreateUniquePath(string fileName)
    {
      return PartPath + "/" + fileName;
    }

    public override string RelationshipType
    {
      get
      {
        return PartRelationshipType;
      }
    }

    public override ContentType ContentType
    {
      get
      {
        return _contentType;
      }
    }

    public override void AddTo(OpenXmlPartCollection parts)
    {
      parts.Add(_targetPath, this);
    }

    public override string TargetPath
    {
      get
      {
        return _targetPath;
      }
    }
  }
}